﻿#include <qg/qg.h>

using namespace tpl;

int main(void)
{
	k_mesg("OFF TEXTURE TEST\n");

	qgDevice* dev = qgDevice::New("", 640, 480, QGSDF_LAYOUT | QGSDF_AUTO);

	if (dev)
	{
		dev->Mount(QG_WORK_PATH);

		qgStub* stub = dev->GetStub();
		qgFreeType* font = qgFreeType::New();

		qgTexture* tex = dev->CreateTexture("/texture/z.png", 0);
		qgTexture* tt = dev->CreateTexture("EmptyTexture", 128, 128, 0, 0, QGTEXF_NOMIP);
		qgTexture* off = dev->CreateTexture("OffTexture", 512, 512, 0, 0, QGTEXF_OFF);
		qgITextureOff* to = off->GetOff();

		//
		while (dev->Run())
		{
			float adv = stub->GetAdvance();

			//
			to->EnterOff();
			dev->DrawRect(Rect(20, 20, 512 - 20, 512 - 20), ColorValues::Blue);
			dev->DrawRect(Rect(40, 40, 512 - 40, 512 - 40), ColorValues::White, tex);
			to->LeaveOff();

			//
			dev->Enter();

			dev->DrawRect(Rect(350, 20, 400, 70), ColorValues::Blue);
			dev->DrawRect(Rect(400, 70, 450, 130), ColorValues::White, tex);

			Rect rt(Point(20, 20), Point(off->GetWidth() / 2, off->GetHeight() / 2));
			dev->DrawRect(rt, tpl::ColorValues::White, off);

			font->WriteFormat(5, 5, 0, "[%.2f]", stub->GetRunFps());

			dev->Leave();
			dev->Flush();
		}

		font->Unload();
		dev->Unload();
	}

	return 0;
}
